package top.mable.utils;

import cn.hutool.core.date.DateTime;
import cn.hutool.core.date.DateUtil;
import cn.hutool.core.util.NumberUtil;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Calendar;
import java.util.Date;

public class DemoTest {

    public static int daysBetween(Date smdate, Date bdate)
            throws ParseException {
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
        smdate = sdf.parse(sdf.format(smdate));
        bdate = sdf.parse(sdf.format(bdate));
        Calendar cal = Calendar.getInstance();
        cal.setTime(smdate);
        long time1 = cal.getTimeInMillis();
        cal.setTime(bdate);
        long time2 = cal.getTimeInMillis();
        double between_days = (time2 - time1) * 1.0 / (1000 * 3600 * 24);
        return (int) Math.ceil(between_days);
    }

    public static void main(String[] args) throws ParseException {
        Date parse = DateUtil.parse("2022-09-19 22:00:00", "yyyy-MM-dd HH:mm:ss");
        System.out.println(parse);
        System.out.println((int)Math.ceil(DateUtil.betweenMs(parse,new Date()) * 1.0 /(1000 * 3600 * 24) ));

        //System.out.println(daysBetween(new Date(),parse));
    }
}
